package com.atguigu.gmall.item.controller;

import com.atguigu.gmall.item.service.ItemService;
import com.atguigu.gmall.item.vo.ItemVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/*
http://item.gmall.com/1626847136220798977.html
 */
@Controller
@RequestMapping
public class ItemController {
    @Resource
    ItemService itemService;
    @GetMapping("{skuId}.html")
    public String item(@PathVariable("skuId")Long skuId,
                       Model model){
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("查询数据详情");
//        System.out.println(skuId);
        //查询商品详情页需要的数据到页面中显示
        ItemVO itemVO = itemService.queryItemBySkuId(skuId);
        model.addAttribute("itemVo" ,itemVO );
        itemService.asyncCreateHtml(itemVO);
//        System.out.println(itemVO);
        stopWatch.stop();
        System.out.println(stopWatch.prettyPrint());
        return "item";
    }
}
